//
//  SwitchLoginTextFieldView.m
//  GaoXunTravel
//
//  Created by 训网高 on 2018/4/11.
//  Copyright © 2018年 May. All rights reserved.
//

#import "SwitchLoginTextFieldView.h"

@implementation SwitchLoginTextFieldView

- (instancetype)initWithFrame:(CGRect)frame withTarget:(id)target withPlaceholderString:(NSString *)placeholder withLeftImageNamed:(NSString *)leftName withRightButton:(BOOL)isShow {
    self = [super initWithFrame:frame];
    if (self) {
        [self setSubViewsWithPlaceholer:placeholder withLeftImage:leftName withwithRightButton:isShow];
        _textField.delegate = target;
    }
    return self;
}

- (void)setSubViewsWithPlaceholer:(NSString *)placeholderString withLeftImage:(NSString *)leftName withwithRightButton:(BOOL)isShow {
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 40, SCREEN_WIDTH-40, 0.5)];
    lineView.backgroundColor = [UIColor whiteColor];
    [self addSubview:lineView];
    
    UIImageView *leftImage = [[UIImageView alloc] initWithFrame:CGRectMake(20, 10, 20, 20)];
    leftImage.image = [UIImage imageNamed:leftName];
    leftImage.contentMode = UIViewContentModeScaleAspectFit;
    [self addSubview:leftImage];
    
    
    _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width-120-20, (40-35)/2, 120, 35)];
    _timeLabel.text = @"获取验证码";
    _timeLabel.textAlignment = NSTextAlignmentCenter;
    _timeLabel.textColor = [UIColor whiteColor];
    _timeLabel.backgroundColor = [UIColor clearColor];
    _timeLabel.layer.borderWidth = 0.5;
    _timeLabel.layer.borderColor = [UIColor whiteColor].CGColor;
    _timeLabel.layer.cornerRadius = 35/2;
    _timeLabel.layer.masksToBounds = YES;
    //验证码
    _codeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _codeBtn.frame = CGRectMake(self.frame.size.width-120-20, (40-35)/2, 120, 35);
//    [_codeBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
    [_codeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _codeBtn.backgroundColor = [UIColor clearColor];
    _codeBtn.layer.borderWidth = 0.5;
    _codeBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    _codeBtn.layer.cornerRadius = 35/2;
    _codeBtn.layer.masksToBounds = YES;
//    if (isHide) {
//        _codeBtn.hidden = YES;
//    }
    if (isShow) {
        [self addSubview:self.timeLabel];
        [self addSubview:_codeBtn];
    }
    
    
   
    
    if (isShow) {
      _textField = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(leftImage.frame)+10, 10, self.frame.size.width-40-20-120-30, 20)];
    } else {
        _textField = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(leftImage.frame)+10, 10, self.frame.size.width-40-30, 20)];
    }
    
    //设置placeholder字体的颜色
    [_textField setAttributedPlaceholder:[[NSAttributedString alloc] initWithString:placeholderString attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}]];
    [_textField setFont:[UIFont systemFontOfSize:14]];
    _textField.textColor = [UIColor whiteColor];
    _textField.placeholder = placeholderString;
    _textField.borderStyle = UITextBorderStyleNone;
    
    [self addSubview:_textField];
}
@end
